package com.qjz.diancan.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qjz.diancan.mapper.DishMapper;
import com.qjz.diancan.model.entity.Dish;
import com.qjz.diancan.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DishServiceImpl implements DishService {
    @Autowired
    private DishMapper dishMapper;

    @Override
    public PageInfo<Dish> findByPage(Integer pageNum, Integer pageSize, String name, Integer categoryId, Integer status)
    {
        PageHelper.startPage(pageNum, pageSize);
        List<Dish> dishList = dishMapper.findByPage(name, categoryId, status);
        return new PageInfo<>(dishList);
    }

    @Override
    public Dish getDishData(Integer id)
    {
        return dishMapper.getDishData(id);
    }

    @Override
    @Transactional
    public void addDishData(Dish dish)
    {
        dishMapper.addDishData(dish);
    }

    @Override
    @Transactional
    public void updateDishDataState(Integer id, Integer state)
    {
        dishMapper.updateDishDataState(id, state);
    }

    @Override
    @Transactional
    public void updateDishData(Dish dish)
    {
        dishMapper.updateDishData(dish);
    }
}
